package com.fliad.ai.mcp.integration;

import com.fliad.ai.mcp.McpServerTool;
import org.noear.dami.Dami;
import org.noear.solon.ai.mcp.server.McpServerEndpointProvider;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;

/**
 * @author wyl
 * @date 2025年05月03日 下午5:17
 */
public class AiMcpPlugin implements Plugin {

    private AppContext appContext = null;

    @Override
    public void start(AppContext context) throws Throwable {
        appContext = context;
        Dami.bus().send("add_no_login_path", "/mcp/sse");
        Dami.bus().send("add_no_login_path", "/mcp/sse/message");
        context.beanMake(McpServerTool.class);
    }

    @Override
    public void prestop() throws Throwable {
        Dami.bus().send("remove_no_login_path", "/mcp/sse");
        Dami.bus().send("remove_no_login_path", "/mcp/sse/message");
        McpServerEndpointProvider mcpServerEndpointProvider = appContext.getBean("McpServerTool");
        mcpServerEndpointProvider.pause();
        mcpServerEndpointProvider.stop();
        appContext = null;
    }

}
